/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package serveursvg;

import java.awt.Point;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import serveursvg.IMessageController.MessageType;

/**
 *
 *
 */
public class RmiServerSvgWriter
        extends UnicastRemoteObject
        implements IRmiServerSvgWriter {

    private MessageSVG svgWriter;

    // friendly is the default access type in java
    // we do not want this to be instanciated outside the package
    RmiServerSvgWriter() throws java.rmi.RemoteException
    {
        svgWriter = new MessageSVG();
    }


    public void exec(MessageType messageType, ArrayList<String> params)
    {
        switch (messageType)
        {
            case REQ:
                svgWriter.dessinerREQClock(Integer.parseInt(params.get(0)),
                        Integer.parseInt(params.get(1)),
                        Integer.parseInt(params.get(2)),
                        Integer.parseInt(params.get(3))
                        );
                break;
            case SC:
                svgWriter.dessinerSC(Integer.parseInt(params.get(0)),
                        Integer.parseInt(params.get(1)),
                        Integer.parseInt(params.get(2)));
                break;
            case REAL:
                svgWriter.dessinerREAL(Integer.parseInt(params.get(0)),
                        Integer.parseInt(params.get(1)),
                        Integer.parseInt(params.get(2)),
                        Integer.parseInt(params.get(3)),
                        params.get(4),
                        params.get(5));
                break;
            case REP:
                svgWriter.dessinerREP(Integer.parseInt(params.get(0)),
                        Integer.parseInt(params.get(1)),
                        Integer.parseInt(params.get(2)),
                        Integer.parseInt(params.get(3)));
                break;
            case PRO:
                svgWriter.dessinerProcessus(Integer.parseInt(params.get(0)));
                break;
            /*
             * it's possible to explicitly ask for svg genration
             * but it will be done after received message anyway
             */
            case GEN:
                svgWriter.genererSVG(params.get(0));
                break;
            case TXT:
                svgWriter.ecrireTexte(new Point(Integer.parseInt(params.get(0)), Integer.parseInt(params.get(1))),
                        params.get(2), params.get(3));
                break;
            case ECL:
                svgWriter.creerEvenementLocal(Integer.parseInt(params.get(0)), Integer.parseInt(params.get(1)));
                break;
            case CLR:
                svgWriter.clearContent();
                break;
        }

        svgWriter.genererSVG("process.svg");
    }
}
